﻿Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server


Partial Public Class StoredProcedures
    <Microsoft.SqlServer.Server.SqlProcedure()> _
    Public Shared Function MSPExecWhoAmI() As Integer
        Dim _sFileNameWithPath As String

        'Just the whoami command
        _sFileNameWithPath = "whoami.exe"

        SqlContext.Pipe.Send("------ > Execution Starts < ------")

        Try
            Dim _oStdOut As System.IO.StreamReader
            Dim _oStdErr As System.IO.StreamReader

            CmdExecNoArguments(_sFileNameWithPath, _oStdOut, _oStdErr)

            OutputResults("--- > Output StdOut < ---", _oStdOut)
            OutputResults("--- > Output StdErr < ---", _oStdErr)

            SqlContext.Pipe.Send(vbCrLf & "------- > Execution Ends < -------")
        Catch ex As Exception
            ShowError(ex.ToString)

            Return 1
        End Try
    End Function
End Class
